package org.ehe.finance.receipt.domain.bo;

import cn.idev.excel.annotation.format.DateTimeFormat;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.github.linpeilie.annotations.AutoMapper;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import lombok.Data;
import org.ehe.common.core.validate.AddGroup;
import org.ehe.common.core.validate.EditGroup;
import org.ehe.common.mybatis.core.domain.BaseEntity2;
import org.ehe.finance.receipt.domain.ErpFinanceReceipt;
import org.ehe.finance.receipt.domain.ErpFinanceReceiptDetail;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

/**
 * 收款单业务对象
 * @author :zhangnn
 * @className :ReceiptBo
 * @description: TODO
 * @date 2025-09-02 14:21:03
 */

@Data
@AutoMapper(target = ErpFinanceReceipt.class)
public class ReceiptBo extends BaseEntity2 {

    /**
     * 收款单ID
     */
    @Schema(description = "收款单ID")
    @NotNull(message = "收款单ID不能为空", groups = { EditGroup.class })
    private Long id;

    /**
     * 收款单号
     */
    @Schema(description = "收款单号")
    @NotBlank(message = "收款单号不能为空", groups = { AddGroup.class, EditGroup.class })
    @Size(max = 50, message = "收款单号长度不能超过{max}个字符")
    @Pattern(regexp = "^[A-Z0-9-]+$", message = "收款单号只能包含大写字母、数字和横线")
    private String receiptNo;

    /**
     * 客户ID
     */
    @Schema(description = "客户ID")
    @NotNull(message = "客户ID不能为空", groups = { AddGroup.class, EditGroup.class })
    @Min(value = 1, message = "客户ID必须大于0")
    private Long customerId;

    /**
     * 收款日期
     */
    @Schema(description = "收款日期")
    @NotNull(message = "收款日期不能为空", groups = { AddGroup.class, EditGroup.class })
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate receiptDate;

    /**
     * 收款账户ID
     */
    @Schema(description = "收款账户ID")
    @NotNull(message = "收款账户ID不能为空", groups = { AddGroup.class, EditGroup.class })
    @Min(value = 1, message = "收款账户ID必须大于0")
    private Long accountId;

    /**
     * 收款总金额
     */
    @Schema(description = "收款总金额")
    @NotNull(message = "收款总金额不能为空", groups = { AddGroup.class, EditGroup.class })
    @DecimalMin(value = "0.01", message = "收款总金额必须大于0")
    @DecimalMax(value = "999999999999.99", message = "收款总金额不能超过{value}")
    @Digits(integer = 12, fraction = 2, message = "收款总金额格式不正确，最多12位整数和2位小数")
    private BigDecimal totalAmount;

    /**
     * 币种ID
     */
    @Schema(description = "币种ID")
    @NotNull(message = "币种ID不能为空", groups = { AddGroup.class, EditGroup.class })
    @Min(value = 1, message = "币种ID必须大于0")
    private Long currencyId;

    /**
     * 汇率
     */
    @Schema(description = "汇率", example = "1.0000")
    @DecimalMin(value = "0.0001", message = "汇率必须大于0")
    @DecimalMax(value = "999999.9999", message = "汇率不能超过{value}")
    @Digits(integer = 6, fraction = 4, message = "汇率格式不正确，最多6位整数和4位小数")
    private BigDecimal exchangeRate = BigDecimal.ONE;

    /**
     * 收款类型:1销售收款,2预收款,3其他收款
     */
    @Schema(description = "收款类型", example = "1", allowableValues = {"1", "2", "3"})
    @NotNull(message = "收款类型不能为空", groups = { AddGroup.class, EditGroup.class })
    @Min(value = 1, message = "收款类型值不正确")
    @Max(value = 3, message = "收款类型值不正确")
    private Integer receiptType;

    /**
     * 收款方式:1现金,2银行转账,3票据,4其他
     */
    @Schema(description = "收款方式", example = "2", allowableValues = {"1", "2", "3", "4"})
    @NotNull(message = "收款方式不能为空", groups = { AddGroup.class, EditGroup.class })
    @Min(value = 1, message = "收款方式值不正确")
    @Max(value = 4, message = "收款方式值不正确")
    private Integer paymentMethod;

    /**
     * 生成凭证ID
     */
    @Schema(description = "生成凭证ID")
    private Long voucherId;

    /**
     * 部门ID
     */
    @Schema(description = "部门ID")
    private Long departmentId;

    /**
     * 业务员ID
     */
    @Schema(description = "业务员ID")
    private Long salesmanId;

    /**
     * 备注
     */
    @Schema(description = "备注")
    @Size(max = 500, message = "备注长度不能超过{max}个字符")
    private String remark;

    /**
     * 状态:1未审核,2已审核
     */
    @Schema(description = "状态:1未审核,2已审核", example = "1", allowableValues = {"1", "2"})
    @Min(value = 1, message = "状态值不正确")
    @Max(value = 2, message = "状态值不正确")
    private Integer status;

    /**
     * 收款明细列表
     */
    @Schema(description = "收款明细列表")
    @Valid
    @NotEmpty(message = "收款明细不能为空", groups = { AddGroup.class, EditGroup.class })
    @Size(min = 1, max = 100, message = "收款明细数量必须在{min}-{max}之间")
    private List<ReceiptDetailBo> receiptDetails;

    // 查询条件字段

    /**
     * 客户名称（查询条件）
     */
    @Schema(description = "客户名称（查询条件）")
    @Size(max = 100, message = "客户名称长度不能超过{max}个字符")
    private String customerName;

    /**
     * 收款日期开始（查询条件）
     */
    @Schema(description = "收款日期开始（查询条件）")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate receiptDateStart;

    /**
     * 收款日期结束（查询条件）
     */
    @Schema(description = "收款日期结束（查询条件）")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate receiptDateEnd;

    /**
     * 收款金额最小值（查询条件）
     */
    @Schema(description = "收款金额最小值（查询条件）")
    @DecimalMin(value = "0", message = "收款金额最小值不能小于0")
    private BigDecimal totalAmountMin;

    /**
     * 收款金额最大值（查询条件）
     */
    @Schema(description = "收款金额最大值（查询条件）")
    @DecimalMin(value = "0", message = "收款金额最大值不能小于0")
    private BigDecimal totalAmountMax;

}
